<?php

/**
 * This is the model class for table "tbl_outpatient_prescriptions".
 *
 * The followings are the available columns in table 'tbl_outpatient_prescriptions':
 * @property string $pk_outpatient_prescription_id
 * @property integer $invalid
 * @property string $invalid_time
 * @property string $fk_doctor_id
 * @property string $fk_outpatient_id
 * @property string $diagnosis
 * @property string $exhort
 * @property string $remarks
 * @property string $create_time
 * @property string $update_time
 * @property string $medicine
 * @property string $del_reason
 */
class TblOutpatientPrescriptions extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_outpatient_prescriptions';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('fk_doctor_id, fk_outpatient_id, create_time, update_time', 'required'),
			array('invalid', 'numerical', 'integerOnly'=>true),
			array('fk_doctor_id, fk_outpatient_id', 'length', 'max'=>20),
			array('diagnosis, exhort, remarks, del_reason', 'length', 'max'=>500),
			array('invalid_time, medicine', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('pk_outpatient_prescription_id, invalid, invalid_time, fk_doctor_id, fk_outpatient_id, diagnosis, exhort, remarks, create_time, update_time, medicine, del_reason', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pk_outpatient_prescription_id' => 'Pk Outpatient Prescription',
			'invalid' => 'Invalid',
			'invalid_time' => 'Invalid Time',
			'fk_doctor_id' => 'Fk Doctor',
			'fk_outpatient_id' => 'Fk Outpatient',
			'diagnosis' => 'Diagnosis',
			'exhort' => 'Exhort',
			'remarks' => 'Remarks',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
			'medicine' => 'Medicine',
			'del_reason' => 'Del Reason',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pk_outpatient_prescription_id',$this->pk_outpatient_prescription_id,true);
		$criteria->compare('invalid',$this->invalid);
		$criteria->compare('invalid_time',$this->invalid_time,true);
		$criteria->compare('fk_doctor_id',$this->fk_doctor_id,true);
		$criteria->compare('fk_outpatient_id',$this->fk_outpatient_id,true);
		$criteria->compare('diagnosis',$this->diagnosis,true);
		$criteria->compare('exhort',$this->exhort,true);
		$criteria->compare('remarks',$this->remarks,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('medicine',$this->medicine,true);
		$criteria->compare('del_reason',$this->del_reason,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TblOutpatientPrescriptions the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
